package com.founder.gateway.component.transport.netty.filter;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.founder.gateway.component.transport.netty.exception.NettyException;
import com.founder.gateway.component.transport.netty.extension.support.AbstractNettyHttpFilter;
import com.founder.gateway.component.transport.netty.http.NettyHttpRequest;
import com.founder.gateway.component.transport.netty.http.NettyHttpResponse;
import com.founder.gateway.orm.fzapi.bean.entity.ApiEntityEntity;
import com.founder.gateway.orm.fzapi.bean.entity.ApiSchemeEntity;

public class NettyFilterChain {
    private List<AbstractNettyHttpFilter> filters = new ArrayList<>();
    private ApiSchemeEntity apiSchemeEntity;
    private ApiEntityEntity apiEntityEntity;
    private int index = 0;

    public void doFilter(NettyHttpRequest request, NettyHttpResponse response) throws IOException, NettyException {
        if (index < filters.size()) {
            filters.get(index++).doFilter(request, response, this);
        }
    }

    public void registerFilter(AbstractNettyHttpFilter filter) {
        filters.add(filter);
    }

    public ApiSchemeEntity getApiSchemeEntity() {
        return apiSchemeEntity;
    }

    public void setApiSchemeEntity(ApiSchemeEntity apiSchemeEntity) {
        this.apiSchemeEntity = apiSchemeEntity;
    }

    public ApiEntityEntity getApiEntityEntity() {
        return apiEntityEntity;
    }

    public void setApiEntityEntity(ApiEntityEntity apiEntityEntity) {
        this.apiEntityEntity = apiEntityEntity;
    }
}
